window.K=window.K||{"URL":{"defaultTemplates":""}};
window._jstemplates=window._jstemplates||{};
K=$.extend(K,{
	"HeaderBar":{
		"View":null,
		"template":{"name":"default","url":"template.html"},
		"installation":function(){
			K.HeaderBar.View=Backbone.View.extend({
			    "tagName":"div",
			    "className":"el-wrapper bg-c1",
			    "template":_.template($("#_template>#t_headerbar").text()),
			    "data":false,
				"dataURL":false,
				"wrapper":null,
				"events":{"onclick":function(){},"onsearch":function(){}},
				"logoBGC":false,
				"logoTip":false,
			    "render":function(json){  
			        this.$el.html(this.template(this.data||json));
			        this.$el.css("height","100%").css("min-height","50px");
			        return this.$el;
			     },"setData":function(data_url){
			    	if(typeof(data_url)=="string")this.dataURL=data_url;
			    	else{this.data=data_url;}
			    	return this;
			     },"setURL":function(url){
			    	this.dataURL=url;
			    	return this;
				 },"to":function($dom){
			    	 if(this.data){
			    		this.render(this.data);
			    		$dom.append(this.$el);
			    		this.activate();
			    	 }else
			    	{
			    		$.ajax({"url":this.dataURL||K.URL.headerBar,"dataType":"json","data":{"_":$.now()},
			    				"dom":$dom,"_this":this}).done(function(json){
							this._this.render(json);
							this.dom.append(this._this.$el);
							this._this.activate();
						}).fail(function(e1,e2,e3){
							K.Tool.log(e2);
						});
			    	}
			    	 return this;
			    },"activate":function(){
			    	if(this.logoBGC)this.$el.find(".top-logo").css("background-color",this.logoBGC);
			    	if(this.logoTip)this.$el.find(".top-logo").attr("title",this.logoTip);
			    	var $keywords=this.$el.find(".search-txt"),$submit=this.$el.find(".search-submit");
			    	$submit.off("mousedown");
			    	$submit.on("mousedown",function(_this,$keywords){
			    		return function(){
			    			if($.trim($keywords.val()).length>0)
			    			_this.events.onsearch($.trim($keywords.val()));
			    		};
			    	}(this,$keywords));
			    	$keywords.off("keyup");
			    	$keywords.on("keyup",function(_this,$keywords){
			    		return function(event){
			    			if(event.keyCode==13&&$.trim($keywords.val()).length>0){
			    				_this.events.onsearch($.trim($keywords.val()));
			    			}
			    		};
			    	}(this,$keywords));
			    	return this;
			    },"click":function(fn){
			    	if(typeof(fn)=="function"){this.events.onclick=fn;}
			    	return this;
			    },"search":function(fn){
			    	if(typeof(fn)=="function"){this.events.onsearch=fn;}
			    	return this;
			    },"setLogoBGColor":function(color){
			    	this.logoBGC=color;
			    	this.activate();
			    	return this;
			    },"setLogoTip":function(tip){
			    	this.logoTip=tip;
			    	this.activate();
			    	return this;
			    }
			});
		},"init":function($dom){
			$dom.empty();
			var hb=new K.HeaderBar.View();
			hb.to($dom);
			return hb;
		}
	}
});
$.extend(_jstemplates,{"HeaderBar":function(cb){
	if($("#_template").length<=0){
		$("body").append($("<div type='text/template' id='_template' />"));
	}
	var arr=[];
	arr.push('<script id="t_headerbar" type="text/template">');
	arr.push('{if(typeof(logo)!="undefined"){}');
	arr.push('{if(typeof(logo)=="string"){}');
	arr.push('<div class="top-logo" style="background-image:url({-logo});"></div>');
	arr.push('{}else if(typeof(logo)=="object"){}');
	arr.push('<div class="top-logo" style="{if(typeof(logo.width)=="string"){}width:{-logo.width};{}}{if(typeof(logo.url)=="string"){}background-image:url({-logo.url});{}}{if(typeof(logo.bgcolor)=="string"){}background-color:{-logo.bgcolor}{}}" title="{-logo.tip}"></div>');
	arr.push('{}}');
	arr.push('{}}');
	arr.push('{if(typeof(search)!="undefined"){}');
	arr.push('{if(typeof(search)=="string"){}');
	arr.push('<div class="adv-search-btn"></div>');
	arr.push('<div class="adv-search-wrapper">');
	arr.push('<input class="search-txt" placeholder="{-search}" />');
	arr.push('<div class="search-submit"></div>');
	arr.push('</div>');
	arr.push('{}else if(typeof(search)=="object"){}');
	arr.push('{if(typeof(search.advance)!="undefined"&&search.advance){}');
	arr.push('<div class="adv-search-btn"></div>');
	arr.push('{}}');
	arr.push('<div class="adv-search-wrapper">');
	arr.push('<input class="search-txt" placeholder="{-search.label||"Search..."}" />');
	arr.push('<div class="search-submit"></div>');
	arr.push('</div>');
	arr.push('{}}');
	arr.push('{}}');
	arr.push('{if(typeof(buttons)!="undefined"){}');
	arr.push('{for(var i=buttons.length-1;i>=0;i--){var button=buttons[i];}');
	arr.push('<div class="top-right-btn {-button.icon}" title="{-button.text}"></div>');
	arr.push('{}}');
	arr.push('{}}');
	arr.push('</script>');
	if($("#_template").find("#t_headerbar").length<=0)
	$("#_template").append(arr.join(""));
	if(typeof(cb)=="function")cb();

}});